package com.hulushuju.core.net.proxy;

import lombok.AllArgsConstructor;
import okhttp3.*;

/**
 * @Author: Hanjiafeng
 * @Date: 2019-05-27
 * @Desc: 代理认证器
 */
@AllArgsConstructor
public class ProxyAuthenticator implements Authenticator {
    /**
     * 代理用户名
     */
    private String username;
    /**
     * 代理密码
     */
    private String password;

    @Override
    public Request authenticate(Route route, Response response) {
        String credential = Credentials.basic(username, password);
        return response.request().newBuilder()
                .header("Proxy-Authorization", credential)
                .build();
    }
}
